home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / vfs / tar.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  6.6 KB  |  236 lines

  1. /* Declarations for the tarfs.
  2.    Copyright (C) 1995 The Free Software Foundation
  3.    
  4.    Written by: 1995 Jakub Jelinek
  5.  
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #if 0
  21. #include "testpad.h"
  22. #else
  23. #define NEEDPAD
  24. #endif
  25.  
  26. #include <sys/types.h>
  27.  
  28. /* major() and minor() macros (among other things) defined here for hpux */
  29. #ifdef hpux
  30. #include <sys/mknod.h>
  31. #endif
  32.  
  33. /*
  34.  * Header block on tape.
  35.  *
  36.  * I'm going to use traditional DP naming conventions here.
  37.  * A "block" is a big chunk of stuff that we do I/O on.
  38.  * A "record" is a piece of info that we care about.
  39.  * Typically many "record"s fit into a "block".
  40.  */
  41. #define    RECORDSIZE    512
  42. #define    NAMSIZ        100
  43. #define    TUNMLEN        32
  44. #define    TGNMLEN        32
  45. #define SPARSE_EXT_HDR  21
  46. #define SPARSE_IN_HDR    4
  47.  
  48. struct sparse {
  49.     char offset[12];
  50.     char numbytes[12];
  51. };
  52.  
  53. struct sp_array {
  54.     int offset;
  55.     int numbytes;
  56. };
  57.  
  58. union record {
  59.     char charptr[RECORDSIZE];
  60.     struct header {
  61.     char arch_name[NAMSIZ];
  62.     char mode[8];
  63.     char uid[8];
  64.     char gid[8];
  65.     char size[12];
  66.     char mtime[12];
  67.     char chksum[8];
  68.     char linkflag;
  69.     char arch_linkname[NAMSIZ];
  70.     char magic[8];
  71.     char uname[TUNMLEN];
  72.     char gname[TGNMLEN];
  73.     char devmajor[8];
  74.     char devminor[8];
  75.     /* these following fields were added by JF for gnu */
  76.     /* and are NOT standard */
  77.     char atime[12];
  78.     char ctime[12];
  79.     char offset[12];
  80.     char longnames[4];
  81. #ifdef NEEDPAD
  82.     char pad;
  83. #endif
  84.     struct sparse sp[SPARSE_IN_HDR];
  85.     char isextended;
  86.     char realsize[12];    /* true size of the sparse file */
  87.     /* char    ending_blanks[12];*//* number of nulls at the
  88.        end of the file, if any */
  89.     } header;
  90.     struct extended_header {
  91.     struct sparse sp[21];
  92.     char isextended;
  93.     } ext_hdr;
  94. };
  95.  
  96. /* The checksum field is filled with this while the checksum is computed. */
  97. #define    CHKBLANKS    "        "    /* 8 blanks, no null */
  98.  
  99. /* The magic field is filled with this if uname and gname are valid. */
  100. #define    TMAGIC        "ustar  "    /* 7 chars and a null */
  101.  
  102. /* The linkflag defines the type of file */
  103. #define    LF_OLDNORMAL    '\0'    /* Normal disk file, Unix compat */
  104. #define    LF_NORMAL    '0'    /* Normal disk file */
  105. #define    LF_LINK        '1'    /* Link to previously dumped file */
  106. #define    LF_SYMLINK    '2'    /* Symbolic link */
  107. #define    LF_CHR        '3'    /* Character special file */
  108. #define    LF_BLK        '4'    /* Block special file */
  109. #define    LF_DIR        '5'    /* Directory */
  110. #define    LF_FIFO        '6'    /* FIFO special file */
  111. #define    LF_CONTIG    '7'    /* Contiguous file */
  112. /* Further link types may be defined later. */
  113.  
  114. /* Note that the standards committee allows only capital A through
  115.    capital Z for user-defined expansion.  This means that defining something
  116.    as, say '8' is a *bad* idea. */
  117. #define LF_DUMPDIR    'D'    /* This is a dir entry that contains
  118.                        the names of files that were in
  119.                        the dir at the time the dump
  120.                        was made */
  121. #define LF_LONGLINK    'K'    /* Identifies the NEXT file on the tape
  122.                        as having a long linkname */
  123. #define LF_LONGNAME    'L'    /* Identifies the NEXT file on the tape
  124.                        as having a long name. */
  125. #define LF_MULTIVOL    'M'    /* This is the continuation
  126.                        of a file that began on another
  127.                        volume */
  128. #define LF_NAMES    'N'    /* For storing filenames that didn't
  129.                        fit in 100 characters */
  130. #define LF_SPARSE    'S'    /* This is for sparse files */
  131. #define LF_VOLHDR    'V'    /* This file is a tape/volume header */
  132. /* Ignore it on extraction */
  133.  
  134. /*
  135.  * Exit codes from the "tar" program
  136.  */
  137. #define    EX_SUCCESS    0    /* success! */
  138. #define    EX_ARGSBAD    1    /* invalid args */
  139. #define    EX_BADFILE    2    /* invalid filename */
  140. #define    EX_BADARCH    3    /* bad archive */
  141. #define    EX_SYSTEM    4    /* system gave unexpected error */
  142. #define EX_BADVOL    5    /* Special error code means
  143.                    Tape volume doesn't match the one
  144.                    specified on the command line */
  145.  
  146. /*
  147.  * We default to Unix Standard format rather than 4.2BSD tar format.
  148.  * The code can actually produce all three:
  149.  *    f_standard    ANSI standard
  150.  *    f_oldarch    V7
  151.  *    neither        4.2BSD
  152.  * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
  153.  * The only advantage to the "neither" option is that we can cmp our
  154.  * output to the output of 4.2BSD tar, for debugging.
  155.  */
  156. #define        f_standard        (!f_oldarch)
  157.  
  158. #ifndef TAR_NAMES
  159.  
  160. struct tarfs_inode;
  161.  
  162. struct tarfs_entry {
  163.     int has_changed;
  164.     long header_offset; /* -1 if not in stored in archive */
  165.     int header_size;
  166.     struct tarfs_entry *next_in_dir;
  167.     struct tarfs_entry *dir;
  168.     long extended_offset; /* -1 if not present */
  169.     int extended_size;
  170.     
  171.     char *name;
  172.     struct tarfs_inode *inode;
  173. };
  174.  
  175. struct tarfs_archive;
  176.  
  177. struct tarfs_inode {
  178.     int has_changed;
  179.     int is_open;
  180.     nlink_t nlink;
  181.     struct tarfs_entry *first_in_subdir; /* only used if linkflag == L_DIR */
  182.     struct tarfs_entry *last_in_subdir;
  183.     long data_offset; 
  184.     char *local_filename;
  185.     ino_t inode;        /* This is inode # */
  186.     dev_t dev;        /* This is an internal identification of the tar archive */
  187.     struct tarfs_archive *archive; /* And this is an archive structure */
  188.     dev_t rdev;
  189.     int std;        /* 0 if old Unix inode */
  190.     
  191.     umode_t mode;
  192.     uid_t uid;
  193.     gid_t gid;
  194.     int size;
  195.     time_t mtime;
  196.     char linkflag;
  197.     char *linkname;
  198.     time_t atime;
  199.     time_t ctime;
  200. };
  201.  
  202. struct tarfs_archive {
  203.     char *name;
  204.     struct stat tarstat;
  205.     int is_gzipped;
  206.     dev_t rdev;
  207.     ino_t __inode_counter;
  208.     struct tarfs_entry *root_entry;
  209.     struct tarfs_entry *current_dir;
  210.     struct tarfs_archive *next;
  211.     long current_tar_position;
  212.     int fd;
  213.     int fd_usage; /* Zero means fd is invalid, otherwise is number of
  214.                      pseudofiles that have the archive open */
  215.     char *tmpname; /* For case of is_gzipped == 2 */
  216. /* This part is only for gzipped archives: (growable buffers) */
  217.     union record *block_first;
  218.     int count_first; /* In records */
  219.     union record **block_ptr;
  220.     int count_blocks; /* In blocks */
  221.     union record *current_record; /* position when reading */
  222. };
  223.  
  224. /* This constant determines how many RECORDSIZE blocks are in one growing
  225.    chunk */
  226. #define TAR_GROWING_CHUNK_SIZE 64
  227.  
  228. enum {
  229.     tar_normal,
  230.     targz_growing,
  231.     tar_uncompressed_local
  232. };
  233.  
  234. #endif /* ! TAR_NAMES */
  235.  
  236.